#define quickread
#ifdef quickread
#include <cstdio> 
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}
template <typename T>
inline void quickwrite(T x)
{
    if(x<0) putchar('-'), x*=-1;
    if(x>=10) quickwrite(x/10);
    putchar(x%10+'0');
}
#else 
#include <iostream>
#endif
#include <deque>
using namespace std;
#define DEBUG
#define int long long
const int N=3e5+10;
int n, m, ans=-1e8, bombs[N], sum[N];
deque<int> q;

void init()
{
    read(n), read(m);
    for(int i=1; i<=n; i++) read(sum[i]), sum[i]+=sum[i-1];
}

void solve()
{
    init();
    q.push_back(0);
    for(int i=1; i<=n; i++)
    {
        if(!q.empty()&&q.front()<i-m) q.pop_front(); //移出越界下标
        ans=max(ans, sum[i]-sum[q.front()]); //计算当前最大子数组和
        while(!q.empty()&&sum[q.back()]>=sum[i]) q.pop_back(); //维护队列单调递增
        q.push_back(i); //找到比队尾前缀和大的后再存入
    }
    quickwrite(ans);
    puts("");
}

// #undef DEBUG
signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        freopen("../out.txt", "w", stdout);
    #endif
    #ifndef quickread
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #endif

    int T=1; //scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}
